home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
- Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
- Begin VB.Form frmChat
- Caption = "Chat"
- ClientHeight = 3915
- ClientLeft = 165
- ClientTop = 735
- ClientWidth = 4590
- LinkTopic = "Form1"
- ScaleHeight = 3915
- ScaleWidth = 4590
- StartUpPosition = 3 'Windows Default
- Begin MSComctlLib.StatusBar sbrChat
- Align = 2 'Align Bottom
- Height = 375
- Left = 0
- TabIndex = 1
- Top = 3540
- Width = 4590
- _ExtentX = 8096
- _ExtentY = 661
- Style = 1
- _Version = 393216
- BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628}
- NumPanels = 1
- BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628}
- AutoSize = 1
- Object.Width = 7594
- EndProperty
- EndProperty
- End
- Begin MSWinsockLib.Winsock sckTCP
- Left = 120
- Top = 3000
- _ExtentX = 741
- _ExtentY = 741
- _Version = 393216
- End
- Begin VB.TextBox txtChat
- Height = 2895
- Left = 0
- MultiLine = -1 'True
- ScrollBars = 2 'Vertical
- TabIndex = 0
- Top = 0
- Width = 4215
- End
- Begin VB.Menu mnuConnect
- Caption = "&Connect!"
- End
- Begin VB.Menu mnuDisconnect
- Caption = "&Disconnect!"
- End
- Attribute VB_Name = "frmChat"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Option Explicit
- Dim mlngBytes As Long
- 'Start out listening for connection
- 'requests
- Private Sub Form_Load()
- 'Set the port to listen on
- sckTCP.LocalPort = 1002
- 'Begin listening
- sckTCP.Listen
- 'Update status bar
- ShowText "Listening"
- End Sub
- Private Sub Form_Resize()
- txtChat.Width = Me.ScaleWidth
- txtChat.Height = Me.ScaleHeight - sbrChat.Height
- sbrChat.Panels(1).Width = Me.ScaleWidth - 300
- End Sub
- Private Sub mnuConnect_Click()
- Dim strRemoteHost As String
- 'Get the name of a computer to connect to
- strRemoteHost = InputBox("Enter name or IP address of computer " & _
- "to connect to.", vbOKCancel)
- 'Exit if cancelled
- If strRemoteHost = "" Then Exit Sub
- 'Close any open connections
- sckTCP.Close
- 'Set the name of the computer to connect to
- sckTCP.RemoteHost = strRemoteHost
- 'Specify a port number on remote host
- sckTCP.RemotePort = 1002
- 'This seems to prevent some TCP errors
- DoEvents
- 'Request the connection
- sckTCP.Connect
- End Sub
- Private Sub mnuDisconnect_Click()
- sckTCP.Close
- DoEvents
- sckTCP.Listen
- ShowText "Listen"
- End Sub
- Private Sub sckTCP_Close()
- ShowText "Close"
- 'When connection by remote machine, go back to listening
- sckTCP.Close
- sckTCP.Listen
- ShowText "Listen"
- End Sub
- Private Sub sckTCP_Connect()
- ShowText "Connected"
- End Sub
- Private Sub sckTCP_ConnectionRequest(ByVal requestID As Long)
- sckTCP.Close
- sckTCP.Accept requestID
- ShowText "Accepting request from " & sckTCP.RemoteHostIP
- End Sub
- Private Sub sckTCP_DataArrival(ByVal bytesTotal As Long)
- Dim strText As String
- 'Get data
- sckTCP.GetData strText
- 'Display data received
- txtChat = txtChat & ">>" & strText & vbCrLf
- 'Move cursor to end
- txtChat.SelStart = Len(txtChat)
- ShowText "Bytes received: " & bytesTotal
- End Sub
- 'Display error information
- Private Sub sckTCP_Error(ByVal Number As Integer, _
- Description As String, ByVal Scode As Long, _
- ByVal Source As String, ByVal HelpFile As String, _
- ByVal HelpContext As Long, CancelDisplay As Boolean _
- ShowText "Error " & Number & " " & Description
- End Sub
- Private Sub sckTCP_SendComplete()
- ShowText "Bytes sent: " & mlngBytes
- End Sub
- Private Sub sckTCP_SendProgress(ByVal bytesSent As Long, ByVal bytesRemaining As Long)
- 'Record number of bytes sent
- mlngBytes = bytesSent
- End Sub
- Private Sub txtChat_KeyPress(KeyAscii As Integer)
- Static strSend As String
- 'Make sure there is a connection
- If sckTCP.State <> sckConnected Then Exit Sub
- 'Send data when user presses Enter
- If KeyAscii = Asc(vbCr) Then
- 'Send the string
- sckTCP.SendData strSend
- 'Clear the variable
- strSend = ""
- Else
- 'Keep track of what is being typed
- strSend = strSend & Chr(KeyAscii)
- End If
- End Sub
- Sub ShowText(Text As String)
- sbrChat.Panels(1).Text = Text
- End Sub
-